package com.iweb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket() {

        // 配置自定义返回状态码
//        List<ResponseMessage> responseMessageList = new ArrayList<>();
//        responseMessageList.add(new ResponseMessageBuilder().code(ResultCode.SUCCESS.code()).message("执行成功").build());
//        responseMessageList.add(new ResponseMessageBuilder().code(ResultCode.FAIL.code()).message("执行失败").build());
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")// 请求的路径
                // 设置自定义返回状态码
//                .useDefaultResponseMessages(false) // 不使用默认的返回状态码
//                .globalResponseMessage(RequestMethod.GET, responseMessageList)
//                .globalResponseMessage(RequestMethod.POST, responseMessageList)
//                .globalResponseMessage(RequestMethod.PUT, responseMessageList)
//                .globalResponseMessage(RequestMethod.DELETE, responseMessageList)
                .select()
                // 扫描接口的路径
                .apis(RequestHandlerSelectors.basePackage("com.iweb.controller"))
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title("ISDN接口文档")
                        .description("ISDN restful 接口开发文档")
                        .version("1.0")
                        .contact(new Contact("jack", "http://www.iweb-edu.com/", "36956271@qq.com"))
                        .license("南京艾瑞职业培训学校")
                        .licenseUrl("http://www.iweb-edu.com/")
                        .build());
    }
}
